
# ======================================================================
# Project:    Closed borders, closed minds? COVID-related border closures,
#             EU support and hostility towards immigrants
#
# Script:     General descriptive and Table E1
#
# Authors:    Lisa Herbig (l.j.herbig@uva.nl)
#             Asli Unan (a.unan@uva.nl)
#
# Date:       2025-03-24
# ======================================================================

# Description:
# This script generates descriptive statistics and Appendix Table E1 (Balance Table). 

# ----------------------------------------------------------------------
# Load libraries
# ----------------------------------------------------------------------
library(arsenal)
library(dplyr)
library(estimatr)
library(dplyr)
library(foreign)
library(ggplot2)
library(haven)
library(lmtest)
library(lubridate)
library(modelsummary)
library(rdrobust)
library(readr)     
library(readxl)
library(tibble)
library(tidyquant)
library(tidyr)
library(tidyverse)
library(xtable)

df_iso_work_dd = readRDS("~/work/November_2024/R_out/df_iso_work_dd_25.rds")

df_iso_work_dd2020 <- df_iso_work_dd %>%
  +   filter(syear == "2020")

table(df_iso_work_dd2020$syear)

######## alone
table(df_iso_work_dd$any_closure_binary_control0)

############## by iso
table(df_iso_work_dd$any_closure_binary_control0, df_iso_work_dd$iso2.y)

table(df_iso_work_dd$any_closure_binary, df_iso_work_dd$iso2.y)

table(df_iso_work_dd$internal_closure_binary_control0, df_iso_work_dd$iso2.y)

table(df_iso_work_dd$internal_closure_binary, df_iso_work_dd$iso2.y)

table(df_iso_work_dd$external_closure_binary_control0, df_iso_work_dd$iso2.y)

table(df_iso_work_dd$external_closure_binary, df_iso_work_dd$iso2.y)

table(df_iso_work_dd2020$any_closure_binary_control0, df_iso_work_dd2020$iso2.y)

table(df_iso_work_dd2020$any_closure_binary, df_iso_work_dd2020$iso2.y)

table(df_iso_work_dd2020$internal_closure_binary_control0, df_iso_work_dd2020$iso2.y)

table(df_iso_work_dd2020$internal_closure_binary, df_iso_work_dd2020$iso2.y)

table(df_iso_work_dd2020$external_closure_binary_control0, df_iso_work_dd2020$iso2.y)

table(df_iso_work_dd2020$external_closure_binary, df_iso_work_dd2020$iso2.y)

######Appendix Figure E1

#1. descriptives of covariates 
  #pn
  desc=df_iso_work_dd2020 %>%
  +   select(East, age_n, iso2_pop, female_pn, unemployed_pn, working_abroad_pn, university_pn, EU_residence_pn, mode_phone_pn,
             +          kr_inz_rate, CONTACTABROAD_pn, HOMEOFFICE_pn, Voting_2018_LeftRight_pn, any_closure_binary_control0, lockdown)

summary(tableby(any_closure_binary_control0 ~., data=desc), text=TRUE)
summary(tableby(any_closure_binary_control0 ~., data=desc), text="latex")

#n
  desc=df_iso_work_dd2020 %>%
  +   select(East, age_n, iso2_pop, female_n, unemployed_n, working_abroad_n, university_n, EU_residence_n, mode_phone_n,
             +          kr_inz_rate, CONTACTABROAD_n, HOMEOFFICE_n, Voting_2018_LeftRight_n, any_closure_binary_control0, lockdown)

summary(tableby(any_closure_binary_control0 ~., data=desc), text=TRUE)
summary(tableby(any_closure_binary_control0 ~., data=desc), text="latex")

#2. descriptives of main outcome variables
  #pn
  desc=df_iso_work_dd2020 %>%
  +   select(con_europe_n, AfD_pn, immigration_pca_n, refugee_eco_n, refugee_culture_n, refugee_ger_living_n, any_closure_binary_control0)

summary(tableby(any_closure_binary_control0 ~., data=desc), text=TRUE)
summary(tableby(any_closure_binary_control0 ~., data=desc), text="latex")
